import re

class SimpleParser:
    def __init__(self, elem):
        self.elem = elem
        self.tagName = ""
        self.params = dict()
        m = re.match('(?s)<(\w+)\s+(.*?)\s*[\/]*>', elem)
        if m:
            self.tagName = m.group(1)
            m = re.findall('\s*(.*?=\".*?\")\s*', m.group(2))
            if m:
                for param in m:
                    mm = re.match('(.*?)=\"(.*)\"', param)
                    if mm:
                        self.params[mm.group(1)] = mm.group(2)
            m = re.match('(?s)<{0}.*?>(.*)<\/{0}>'.format(self.tagName), elem)
            if m:
                ss = m.group(1)
                m = re.findall('(?s)<(\w+).*?>(.*?)<\/', ss)
                for p in m:
                    self.params[p[0]] = p[1]
                    
    def toObj(self, obj):
        for p in self.params.keys():
            if hasattr(obj, p):
                setattr(obj, p, self.params[p])

if __name__ == "__main__":
    class TestGame:
        def __init__(self):
            self.id = ""
            self.info = ""
            self.publisher = ""
            
        def __str__(self):
            return "id={0} info={1} publisher={2}".format(self.id, self.info, self.publisher)
    
    s = '''<game id="9147" publisher="4" tournament="451" round="1" rule="1" black="84" white="281" bresult="0" opening="16" alt="11" swap="-">
    <move>h8 h9 j10 i9 g9 i7 i10 g10 k9 l8 i8 j8 h10 i11 e8 f8 e9 e10 h7 j9 d9 f7 f10 d8 f5 g6 c9 f9 b9 a9 c10 e11 e12 d11 c12 c11 b11 a12 i12 k10 j6 l6 l7 m7 k5 g5 e6 g4 g3 f4 h6 m5</move>
    <info>97/88</info>
    </game>'''
    
    sp = SimpleParser(s)
    print sp.tagName
    print sp.params
    
    tg = TestGame()
    sp.toObj(tg)
    print tg
    